package com.info.zhiduoduo.repository.mapper.crowdsource;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.crowdsource.ExportOddJobQTemplateTaskDto;
import com.info.zhiduoduo.repository.dto.crowdsource.ExportOddJobQTemplateUserDto;
import com.info.zhiduoduo.repository.dto.crowdsource.OddJobMerchantFlowDetailDto;
import com.info.zhiduoduo.repository.entity.crowdsource.OddJobMerchantFlow;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author tianyonghong
 * @create 2023/2/23
 */
public interface OddJobMerchantFlowMapper extends BaseMapper<OddJobMerchantFlow> {

    //查询河南的智零工流水业务
    @Select(" select ojmf.*,ccp.company_name as partyName " +
            " from zdd_odd_job_merchant_flow ojmf " +
            " left join zdd_crowdsource_company_party ccp on ojmf.party_id=ccp.id" +
            " where 1 = 1" +
            " and IF(ISNULL(#{merchantId}) or #{merchantId} = 0,1=1, ojmf.merchant_id = #{merchantId}) " +
            " and IF(ISNULL(#{partyId}) or #{partyId} = 0,1=1, ojmf.party_id = #{partyId}) " +
            " and IF(ISNULL(#{startTime}) or #{startTime} = '',1=1, ojmf.create_time >= #{startTime}) " +
            " and IF(ISNULL(#{endTime}) or #{endTime} = '',1=1, ojmf.create_time <= #{endTime}) " +
            " ORDER BY ojmf.create_time DESC ")
    List<OddJobMerchantFlowDetailDto> selectFlowList(Integer merchantId, Integer partyId, Date startTime, Date endTime);

    @Select("SELECT ca.realname,c.phone,ca.idno,ca.acctno,ca.bankname,ca.alipay_logon_id" +
            " from zdd_crowdsource_project_item cpi " +
            " left join zdd_crowdsource c on c.crowdsourceid = cpi.userid" +
            " left join zdd_crowdsource_account ca on ca.crowdsourceid = cpi.userid" +
            " where cpi.deleted = 0 and cpi.projectid = #{projectId}")
    List<ExportOddJobQTemplateUserDto> selectQExportUserList(Integer projectId);

    @Select("SELECT cp.project_name,cpi.project_amount,ca.idno,ca.realname" +
            " from zdd_crowdsource_project_item cpi" +
            " left join zdd_crowdsource_project cp on cpi.projectid = cp.projectid" +
            " left join zdd_crowdsource_account ca on ca.crowdsourceid = cpi.userid" +
            " where cpi.deleted = 0 and cpi.projectid = #{projectId}")
    List<ExportOddJobQTemplateTaskDto> selectQExportTaskList(Integer projectId);
}
